package cn.com.lms.business.examRewrite.service;

import cn.com.lms.business.core.constant.ErrorEnum;
import cn.com.lms.business.exam.persistence.entity.QuestionVO;
import cn.com.lms.business.examRewrite.persistence.entity.*;
import cn.com.lms.business.examRewrite.persistence.repository.QuestionReWriteDao;
import com.bnzj.core.exception.BusinessException;
import com.bnzj.core.persistence.BaseService;
import com.bnzj.core.persistence.query.QueryHelpBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
public class QuestionReWriteService extends BaseService<QuestionReWriteDao, QuestionReWrite,Long> {

    @Autowired
    QuestionCategoryReWriteService questionCategoryReWriteService;

    /**
     * 试题列表的详细信息
     * @return
     */
    public static QueryHelpBean getQueryHelpBean() {
        String selectSQL = "select eq.*,qc.category_name, " +
                "(select count(1) from bnz_exam_question_subject qs where qs.question_id=eq.id and qs.is_delete=0) as  count," +
                "(select count(1) from bnz_exam_question_subject qs where qs.type=1 and qs.question_id=eq.id and qs.is_delete=0) as  single_count," +
                "(select count(1) from bnz_exam_question_subject qs where qs.type=2 and qs.question_id=eq.id and qs.is_delete=0) as  multiple_count," +
                "(select count(1) from bnz_exam_question_subject qs where qs.type=3 and qs.question_id=eq.id and qs.is_delete=0) as  judge_count," +
                "(select count(1) from bnz_exam_question_subject qs where qs.type=4 and qs.question_id=eq.id and qs.is_delete=0) as  fill_count," +
                "(select count(1) from bnz_exam_question_subject qs where qs.type=5 and qs.question_id=eq.id and qs.is_delete=0) as  explain_count";

        String whereSQL = " from bnz_exam_question as eq left join bnz_exam_question_category as qc on qc.id=eq.category_id where 1=1  ";
        QueryHelpBean queryBean = new QueryHelpBean(selectSQL + whereSQL, "select count(1)" + whereSQL, QuestionReWriteVo.class);
        return queryBean;
//        String selectSQL = "SELECT object.*, " +
//                "(SELECT count(1) FROM  bnz_exam_question_subject ees WHERE ees.question_id = object.id AND is_delete = 0) subject_count, " +
//                "(SELECT count(1) FROM  bnz_exam_question_subject ees WHERE ees.question_id = object.id AND is_delete = 0 AND ees.type = 1) singleCount, " +
//                "(SELECT count(1) FROM  bnz_exam_question_subject ees WHERE ees.question_id = object.id AND is_delete = 0 AND ees.type = 2) multipleCount, " +
//                "(SELECT count(1) FROM  bnz_exam_question_subject ees WHERE ees.question_id = object.id AND is_delete = 0 AND ees.type = 3) judgeCount, " +
//                "(SELECT count(1) FROM  bnz_exam_question_subject ees WHERE ees.question_id = object.id AND is_delete = 0 AND ees.type = 4) fillCount, " +
//                "(SELECT count(1) FROM  bnz_exam_question_subject ees WHERE ees.question_id = object.id AND is_delete = 0 AND ees.type = 5) explainCount ";
//        String whereSQL =  "FROM " +
//                "(SELECT eq.*,eqc.category_name FROM bnz_exam_question eq JOIN bnz_exam_question_category eqc WHERE eq.category_id = eqc.id and eq.id " +
//                "IN " +
//                "(SELECT eeq.question_id FROM bnz_exam_exercise_question eeq JOIN bnz_exam_paper ee WHERE eeq.exercise_id = ee.id)) object where 1=1";
//
//        QueryHelpBean queryHelpBean = new QueryHelpBean(selectSQL+whereSQL,"select count(1)" + whereSQL, QuestionReWriteVo.class);
//        return queryHelpBean;
    }



}
